package day07;

import java.util.*;
import java.util.stream.Stream;

public class homework03 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串");
        String str = sc.next();
        System.out.println("请输入目标字符出现的次数");
        int num = sc.nextInt();
        ArrayList<Character> list = new ArrayList<>();
        Stream.of(str.toCharArray()).forEach(s->{
            for (int i = 0; i < str.length(); i++) {
                char strs = str.charAt(i);
                list.add(strs);
            }
        });

        Map<Character, Integer> map = new HashMap<>();
        for (Character str1 : list) {
            if (map.containsKey(str1)) {
                Integer value = map.get(str1);
                value++;
                map.put(str1, value);
            } else {
                map.put(str1, 1);
            }
        }
        map.entrySet().stream().filter(m -> m.getValue() == num).forEach(s -> System.out.println(s.getKey()));
    }
}
